<!DOCTYPE html>
<html>
<head>
    <title>提交文本</title>
    <script>
        async function handleSubmit(e) {
            e.preventDefault();
            const text = e.target.text.value;
            const response = await fetch('/api/texts', {
                method: 'POST',
                body: JSON.stringify({ text }),  // 确保是有效的JSON格式
                headers: {
                    'Content-Type': 'application/json'  // 必须设置这个头
                }
            });
            
            if (response.ok) {
                alert('提交成功！');
                e.target.reset();
            } else {
                alert('提交失败');
            }
        }
    </script>
</head>
<body>
    <h1>提交文本</h1>
    <form onsubmit="handleSubmit(event)">
        <textarea name="text" required></textarea><br>
        <button type="submit">提交</button>
    </form>
    <p><a href="/admin">管理员登录</a></p>
</body>
</html>
